package com.tiankun.eurekaticket.controller;

import com.tiankun.eurekaticket.pojo.Get;
import com.tiankun.eurekaticket.service.GetService;
import com.tiankun.eurekaticket.util.JsonResult;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author liaopeng
 * @Date 2020/11/14 16:07
 * @Version 1.0
 **/
@RestController
@RequestMapping("/get")
@Api(value = "领取优惠券控制器",tags = "领取优惠券接口的api")
public class GetController {

    @Resource
    GetService getService;

    @PostMapping("/getTkt")
    @ApiOperation(value = "领取优惠券的接口",notes = "领取优惠券",httpMethod = "post",response = String.class)
    public Map getTkt(@RequestBody @ApiParam
            (name = "get",value = "领取优惠券的pojo信息",required = true)Get get) {
        Integer integer = getService.insert(get);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("领取成功");
        jsonResult.setCode("1");
        return jsonResult.getValues();
    }

    @PostMapping("/getUnusedList")
    @ApiOperation(value = "用户本人领取未使用未过期的优惠券列表的接口",notes = "获取本人领取优惠券列表的数据",httpMethod = "post",response = String.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone",value = "用户电话号码",required = true,dataType = "String",paramType = "query")
    })
    public Map getUnusedList(@RequestParam("phone") String phone) {
        List<Map<String, Object>> unusedList = getService.getUnusedList(phone);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("查询成功");
        jsonResult.setCode("1");
        jsonResult.setData(unusedList);
        return jsonResult.getValues();
    }

    @PostMapping("/getusedList")
    @ApiOperation(value = "用户本人领取已使用的优惠券列表的接口",notes = "获取本人领取优惠券列表的数据",httpMethod = "post",response = String.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone",value = "用户电话号码",required = true,dataType = "String",paramType = "query")
    })
    public Map getusedList(@RequestParam("phone") String phone) {
        List<Map<String, Object>> usedList = getService.getusedList(phone);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("查询成功");
        jsonResult.setCode("1");
        jsonResult.setData(usedList);
        return jsonResult.getValues();
    }

    @PostMapping("/expiredList")
    @ApiOperation(value = "用户本人领取未使用已过期的优惠券列表的接口",notes = "获取本人领取优惠券列表的数据",httpMethod = "post",response = String.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone",value = "用户电话号码",required = true,dataType = "String",paramType = "query")
    })
    public Map expiredList(@RequestParam("phone") String phone) {
        List<Map<String, Object>> expiredList = getService.expiredList(phone);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("查询成功");
        jsonResult.setCode("1");
        jsonResult.setData(expiredList);
        return jsonResult.getValues();
    }

    @PostMapping("/update")
    public Map update(@RequestParam("id")Integer id,@RequestParam("phone")String phone, @RequestParam("usestate")Integer usestate) {
        Integer update = getService.updatestate(id,phone,usestate);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("已使用");
        jsonResult.setCode("1");
        return jsonResult.getValues();
    }
}
